*********************************************************		
* Replication file for tables and figure in 
* “Reading fiction and economic preferences of rural youth in Burkina Faso”
* Economic Development and Cultural Change 2019
	* Michael Kevane
	* Dept. of Economics
	* Santa Clara University
	* mkevane@scu.edu
*********************************************************		

* Programs might need to install
	*ssc install ingap
	*ssc install estout  

* Programs to find and then install
	*findit matselrc 
	*findit matsave 
	*findit leebounds 
	*findit tsrtest
	*findit permtest2
	*findit leebounds
	*findit strdist

* Set globals 
	clear
	version 12
	set more off 
	dis "`c(username)'"
	* This is for Windows PS; Mac users will have different format
	global user "C:\Users\\`c(username)'\Documents\JTL replication"

* Set language; for tables and figures that alternative titles and labels
	global lang "English"

* Set globals for file structure
	global dta "$user\data"
	global prg "$user\programs"
	global extra "$prg\extra"	
	global pprs "$user\results"
	cd "$user\scrap"

* Load data and create locals list of variables	
	set more off
	use "$dta\JTL_for_EDCC", clear	
	loc propvar female bwaba hasportable abonnee01 villageavecbib misspelltravmere misspelltravpere cantrust treatment
	loc contvar age2013 educannee livres30 titreyes_mars13 
	loc othervar w_group survweight w_partexpmai13 w_partexpaout13  w_didjjeuxmai2014 treatment ///
		cluster titreyesnk_aout13 titreyesnk_mai13  titreyesnk_mars14 titreyesnk_mai14 ///
		contribconf_ weighshare_ contribpub_ patiencecount_  allconsist_  parichoix_ 

* Table 1 - Means and test for difference, for two groups treatment and control, weight each observation by probabilty of inclusion in survey
	eststo clear
	preserve
	foreach var in `propvar' `contvar' `outvar' {
	replace `var'=`var'*survweight
	}
	do "$extra\make table of means and ttest results more than 2 cats.do" ///  /*this computes means/prop for variables according to dummy 0-1 variables*/
	"w_groupnum"	///  /*these are the categorical variables, the BY variable*/
	"`propvar'" /// /*these are the 0-1 variables, test for prop diff*/
	"`contvar'" /// /*these are the continuous variables, ttest for mean diff*/
	"$pprs/Tab 1" /*file location and name of Excel output*/
	restore
	
* Table 2 - For each session, who did and did not participate, weighted by survey weights
	eststo clear
	preserve
	foreach var in `propvar' `contvar' `outvar' {
	replace `var'=`var'*survweight
	}
	do "$extra\make table of means and ttest results more than 2 cats.do" ///  /*this computes means/prop for variables according to dummy 0-1 variables*/
	"w_partexpmai13 w_partexpaout13  w_didjjeuxmai2014"	///  /*these are the categorical variable, the BY variable*/
	"`propvar'" /// /*these are the 0-1 variables, test for prop diff*/
	"`contvar'" /// /*these are the continuous variables, ttest for mean diff*/
	"$pprs/Tab 2 Who participated" /*file location and name of Excel output*/
	restore

* Another way of looking at attrition (included in text of paper)
	foreach var in w_partexpmai13 w_partexpaout13  w_didjjeuxmai2014 {
	prtest `var', by(treatment)
	}

* Table 3 - Means and test for difference, for two groups treatment and control, weight each observation by probabilty of inclusion in survey
	loc outcom_jeu titreyes_mars13 titreyes_mai13 titreyes_aout13 titreyes_mars14 titreyes_mai14 ///
		titrejtlyes_mars13 titrejtlyes_mai13 titrejtlyes_aout13 titrejtlyes_mars14 titrejtlyes_mai14   ///
		persothyes_aout13 persothyes_mai14 persjtlyes_aout13 persjtlyes_mai14 
		
* Table of reading outcomes BY treatment, weighted by survey probability, with ttest for diff in means
	preserve
	foreach var in `outcom_jeu' {
	replace `var'=`var'*survweight
	}
	eststo clear
	do "$extra\make table of means and ttest results more than 2 cats.do" ///  /*this computes means/prop for variables according to dummy 0-1 variables*/
	"treatment"	///  /*these are the categorical variables, the BY variable*/
	" " /// /*these are the 0-1 variables, test for prop diff*/
	"`outcom_jeu' " /// /*these are the continuous variables, ttest for mean diff*/
	"$pprs/Tab 3 Reading outcomes" /*file location and name of Excel output*/
	restore

* Table 4 - Regressions of effects of treatment on reading, measured in August 2013, March 2014, May 2014
	eststo clear
	#delimit ; 
	loc vars1 "treatment educannee female bwaba age2013 villageavecbib i.cluster"; 
	foreach session in mai13 aout13 mars14 mai14 {;
	foreach deppp in  "titreyes_`session'"  "titrejtlyes_`session'"  {;
	quietly eststo, ti(`deppp'): xi: quietly svy:  reg `deppp'  `vars1' titreyes_mars13;
	quietly summarize `deppp' if treatment==0;
    estadd scalar ymean = r(mean) ;
	};
	};
	esttab  using "$pprs/Tab 4 Effects on reading.csv", rep se scalars(ymean) n r2  nonote nonumbers  mtitles label 
	  drop(_Icluster*) star(* 0.10 ** 0.05 *** 0.01) 
	  title("Table 4: Effects of selection into reading program (treatment) on number of books read")  
	  addnotes("Notes: Stata svy estimation used. * p<0.10 ** p<0.05 *** p<0.01 . Dummy variables for village clusters included but not reported."); 
	#delimit cr
	
* Table 4 alt - Regressions of effects of treatment on reading, measured in August 2013, March 2014, May 2014
	eststo clear
	#delimit ; 
	loc vars1 "treatment educannee female bwaba age2013 villageavecbib i.cluster"; 
	foreach session in mai13 aout13 mars14 mai14 {;
	foreach deppp in  "titreyes_`session'"  "titrejtlyesnk_`session'"  {;
	quietly eststo, ti(`deppp'): xi: quietly svy:  reg `deppp' treatment	;
	quietly eststo, ti(`deppp'): xi: quietly svy:  reg `deppp' `vars1';
	quietly eststo, ti(`deppp'): xi: quietly svy:  reg `deppp' titreyes_mars13 `vars1';
	quietly summarize `deppp' if treatment==0;
    estadd scalar ymean = r(mean) ;
	};
	};
	esttab  using "$pprs/Tab 4 Effects on reading_alt.csv", rep se r2 scalars(ymean) nonote nonumbers  mtitles label 
	  drop(_Icluster*) star(* 0.10 ** 0.05 *** 0.01) 
	  title("Table 4: Effects of selection into reading program (treatment) on number of books read")  
	  addnotes("Notes: Stata svy estimation used. * p<0.10 ** p<0.05 *** p<0.01. Dummy variables for village clusters included but not reported."); 
	#delimit cr
	
* Table 5 - Means and standard deviations outcomes by game session
 	eststo clear
	loc i=1
	foreach x in mai13 aout13 mai14 {
	preserve
	keep if sancnum_`x'~=.
	foreach z in contribconf_ weighshare_ contribpub_ patiencecount_  allconsist_  parichoix_ {
	rename `z'`x' `z'
	replace `z'=`z'*survweight
	}
	keep contribconf_ weighshare_ contribpub_ patiencecount_  allconsist_  parichoix_
	gen session=`i'
	save temp_`i', replace
	loc i=`i'+1
	restore
	}
	preserve
	use temp_1, clear
	append using temp_2
	append using temp_3
	format session %9.0g
	do "$extra\make table of means and ttest results more than 2 cats.do" ///  /*this computes means/prop for variables according to dummy 0-1 variables*/
		"session"	///  /*these are the categorical variables, the BY variable*/
		"allconsist_" /// /*these are the 0-1 variables, test for prop diff*/
		"contribconf_ weighshare_ contribpub_ patiencecount_ parichoix_" /// /*these are the continuous variables, ttest for mean diff*/
		"$pprs/Tab 5 means game play by session" /*file location and name of Excel output*/
	restore

	forval i=1(1)3 {
	erase temp_`i'.dta
	}
	

* Table 6 and Table 7- Regressions of effects of treatment on trust and public goods game, measured in May 2013, August 2013, May 2014
	eststo clear
	loc vars1 "treatment female bwaba educannee age2013  i.cluster" 
	foreach game in conf pub {
	foreach session in mai13 aout13 mai14 {
	foreach deppp in "contrib`game'_`session'" "contrib`game'_`session' contrib`game'_mai13" {
	quietly eststo, ti(`deppp'): xi: quietly svy:  reg `deppp' treatment	
	quietly eststo, ti(`deppp'): xi: quietly svy:  reg `deppp' `vars1'
	quietly summarize contrib`game'_`session' if treatment==0
    estadd scalar ymean = r(mean) 
	}
	}
	}
	esttab  using "$pprs/Tab 6a_7 game outcome by program trust_pub.csv", rep nonote nonumbers scalars(ymean) se  r2 mtitles label ///
	  drop(_Icluster*) star(* 0.10 ** 0.05 *** 0.01) ///
	  title("Table 6a_7: Effects of selection into reading program (treatment) on amounts contributed trust and public goods")  ///
	  addnotes("Notes: Estimated using Stata svy regress command. * p<0.10 ** p<0.05 *** p<0.01 .") 

	* Effects of reading program on playing experimental games - amount returned
	eststo clear
	loc vars1 "treatment female bwaba educannee age2013 i.cluster" 
	foreach session in mai13 aout13 mai14 { 
	foreach deppp in "weighshare_`session'" "weighshare_`session' weighshare_mai13" {
	quietly eststo, ti(`deppp'): xi: quietly svy:  reg `deppp' treatment	
	quietly eststo, ti(`deppp'): xi: quietly svy:  reg `deppp' `vars1'
	quietly summarize weighshare_`session' if treatment==0
    estadd scalar ymean = r(mean) 
	}
	}
	esttab  using "$pprs/Tab 6b game outcome by program return frac.csv", rep nonote nonumbers scalars(ymean) se r2 mtitles label ///
	  drop(_Icluster*) star(* 0.10 ** 0.05 *** 0.01) ///
	  title("Table 7b: Effects of selection into reading program (treatment) on trustworthiness in trust game")  ///
	  addnotes("Notes: Estimated using Stata svy regress command. * p<0.10 ** p<0.05 *** p<0.01 .") 
	*/ 
	
* Table 8 and Table 9 - Regressions of effects of treatment on risk and patience game, measured in May 2013, August 2013, May 2014
	eststo clear
	loc vars1 "treatment female bwaba educannee age2013 i.cluster" 
	foreach outcom in patiencecount parichoix {
	foreach session in mai13 aout13 mai14 {
	foreach deppp in "`outcom'_`session'" "`outcom'_`session' `outcom'_mai13"  {
	quietly eststo, ti(`deppp'): xi: quietly svy:  reg `deppp' treatment	
	quietly eststo, ti(`deppp'): xi: quietly svy:  reg `deppp' `vars1'
	quietly summarize `outcom'_`session' if treatment==0
    estadd scalar ymean = r(mean) 
	}
	}
	}
	esttab  using "$pprs/Tab 8_9 game outcome by program patiencerisk.csv", rep nonote  scalars(ymean) se r2 nonumbers mtitles label ///
	  drop(_Icluster*) star(* 0.10 ** 0.05 *** 0.01) ///
	  title("Table 8_9: Effects of selection into reading program (treatment) on choices in patience and risk game")  ///
	  addnotes("Notes: Estimated using Stata svy regress command. * p<0.10 ** p<0.05 *** p<0.01 .") 
 
* Table 10 - Regressions of effects of treatment on survey questions, measured in May 2013, August 2013, May 2014
	eststo clear
	loc vars1 "treatment female bwaba educannee age2013 i.cluster" 
	foreach outcom in trustoverall riskoverall {
	foreach session in mars14 mai14 {
	foreach deppp in "`outcom'_`session'" "`outcom'_`session' cantrust" ///
	"`outcom'_`session'" "`outcom'_`session' `outcom'_mai13" {
	quietly eststo, ti(`deppp'): xi: quietly svy:  reg `deppp' treatment	
	quietly eststo, ti(`deppp'): xi: quietly svy:  reg `deppp' `vars1'
	quietly summarize `outcom'_`session' if treatment==0
    estadd scalar ymean = r(mean) 
	}
	}
	}
	esttab  using "$pprs/Tab 10 survey outcomes.csv", rep nonote nonumbers r2 scalars(ymean)  se mtitles label ///
	  drop(_Icluster*) star(* 0.10 ** 0.05 *** 0.01) ///
	  title("Table 10: Effects of selection into reading program (treatment) on survey question responses")  ///
	  addnotes("Notes: Estimated using Stata svy regress command. * p<0.10 ** p<0.05 *** p<0.01 .") 
	
* Bar graph of reading outcomes BY treatment, weighted by survey probability, with ttest for diff in means
	loc outcom_jeu titreyes_mars13 titreyes_mai13 titreyes_aout13 titreyes_mars14 titreyes_mai14 ///
		titrejtlyes_mars13 titrejtlyes_mai13 titrejtlyes_aout13 titrejtlyes_mars14 titrejtlyes_mai14 ///
		id 
	foreach var in `outcom_jeu' {
	replace `var'=`var'*survweight
	}
	keep `outcom_jeu' treatment
	rename titreyes_mars13 titreyes1 
	rename titreyes_mai13 titreyes2 
	rename titreyes_aout13 titreyes3 
	rename titreyes_mars14 titreyes4 
	rename titreyes_mai14 titreyes5 
	rename titrejtlyes_mars13 titrejtlyes1 
	rename titrejtlyes_mai13 titrejtlyes2 
	rename titrejtlyes_aout13 titrejtlyes3 
	rename titrejtlyes_mars14 titrejtlyes4 
	rename titrejtlyes_mai14 titrejtlyes5 

	reshape long titreyes titrejtlyes, i(treatment id) j(session)
	*try scheme sj and s2mono also
	label define sess 1 "March 2013" 2 "May 2013" 3 "August 2013" 4 "March 2014" 5 "May 2014"
	label values session sess
	label define tc 1 "Trt" 0 "Con" 
	label values treatment tc
	#delimit ;
	graph bar (mean) titreyes , over(treatment, label(labsize(small))) over(session, label(labsize(medsmall)))  bargap(-5)
	  ytitle(" ", size(small)) ylabel(0(.5)2, labsize(small))
	  title("(a) All titles", size(medsmall)) leg(off)
  	  scheme(s1mono) saving(fig1a , replace);
	graph bar (mean) titrejtlyes , over(treatment, label(labsize(small))) over(session, label(labsize(medsmall)))  bargap(-5)
	  ytitle(" ", size(small)) ylabel(0(.5)2, labsize(small))
	  title("(b) JTL book titles only", size(medsmall)) leg(off) /*legend(colgap(10) width(95))*/
  	    scheme(s1mono) saving(fig1b , replace) bgcolor(white) ;
	gr combine "fig1a" "fig1b", title("  "  ,size(med)) cols(1) graphregion(color(white)) ;	 
	graph export "$pprs/Fig 2 bar reading.eps", replace ;
	#delimit cr
	* Title and caption information
	* Figure 2: Average number of titles listed on survey questionnaires
	* caption("Note: 'Con' refers to control group, 'Trt' refers to treatment group.", size(vsmall);
	